package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xxx
 * Date: 2025-03-15
 * Time: 9:15
 */
class Dog{
//访问修饰符 类型   变量
    public String name;//成员变量
    public static int age;//静态成员变量
    //静态代码块
    static{
        age = 18;
    }
    //实例代码块
    {
        name = "小黄";
    }
    //静态成员方法(狗的行为)
    public void bark(){
        System.out.println(name + " 正在汪汪叫");
    }
}
public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
        System.out.println(dog.name);
        System.out.println(dog.age);
    }
}











    /*//实例化对象
    Dog dog1 = new Dog();
//用.号访问成员变量和成员方法(类似于C语言)
        dog1.name = "大黄";
                dog1.age = 3;
                System.out.println(dog1.name);
                System.out.println(dog1.age);
                dog1.bark();*/